package com.thti.mecool.client.model.biz;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.thti.mecool.client.db.DataBase;
import com.thti.mecool.client.model.po.MobileMessages;

public class MessagesBizImpl {
	private DataBase dataBase;

	public MessagesBizImpl(Context context) {
		dataBase = new DataBase(context);
	}
	
	public void save(MobileMessages mobileMessages){
		String sql="insert into messages(id,head,body,priority,type,createdOn) values(?,?,?,?,?,?)";
		dataBase.execObject(sql, new Object[]{mobileMessages.getId(),mobileMessages.getHead(),mobileMessages.getBody()
				,mobileMessages.getPriority(),mobileMessages.getType(),mobileMessages.getCreatedOn()});
		dataBase.close();
	}

	@SuppressWarnings("unchecked")
	public List<MobileMessages> findall(){
		String sql="select id,head,body,priority,type,createdOn from messages";
		List<MobileMessages> list=new ArrayList<MobileMessages>();
		list=dataBase.findAll(MobileMessages.class, sql, new String[]{});
		dataBase.close();
		return list;
		
	}
	
	public void update(String id){
		String sql="update messages set type='READ' where id=?";
		dataBase.execObject(sql, new Object[]{id});
		dataBase.close();
	}
}
